package com.hhw.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hhw.entity.UserRegister;
import com.hhw.service.UserRegisterService;

/**
 * Servlet implementation class Doregister
 */
@WebServlet("/doregister")
public class Doregister extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Doregister() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		 
		request.setCharacterEncoding("UTF-8");
		String error="";
		String user_name=request.getParameter("user_name");
//		System.out.println("user_name");
		String user_password=request.getParameter("user_password");
		String user_sex=request.getParameter("user_sex");
		String user_phone=request.getParameter("user_phone");
		String user_add=request.getParameter("user_add");
		
		UserRegisterService rs=new UserRegisterService();
		UserRegister re=new UserRegister();
		re.setUser_name(user_name);
		re.setUser_password(user_password);
		re.setUser_sex(user_sex);
		re.setUser_phone(user_phone);
		re.setUser_add(user_add);
		
		
		
		boolean b=rs.isExist(re);
		if(b){
			System.out.println("注册失败，请重新注册！");
			request.getRequestDispatcher("/toregister").forward(request, response);
		}else{
			System.out.println("注册成功！");
			int i=rs.addUserRegister(re);
			request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request, response);
		}
	}

}
